package com.itheima.itheima_health.controller.admin.BookingController;

import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.entity.PageResult;
import com.itheima.itheima_health.entity.QueryPageBean;
import com.itheima.itheima_health.entity.Result;
import com.itheima.itheima_health.pojo.CheckGroup;
import com.itheima.itheima_health.pojo.Setmeal;
import com.itheima.itheima_health.service.CheckMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

/**
 * 套餐相关
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "套餐相关")
public class CheckMenuController {
    @Autowired
    private CheckMenuService checkMenuService;

    /**
     * 套餐分页查询
     * @param queryPageBean
     * @return
     */
    @ApiOperation("套餐分页查询")
    @PostMapping("/pageQuery")
    @PreAuthorize("hasAnyAuthority('SETMEAL_QUERY')")
    public PageResult MenuPageQuery(@RequestBody QueryPageBean queryPageBean){
        log.info("套餐分页查询:{}",queryPageBean);
        PageResult pageResult = checkMenuService.MenuPageQuery(queryPageBean);
        return pageResult;
    }

    /**
     * 检查套餐添加
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @ApiOperation("检查套餐添加")
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('SETMEAL_ADD')")
    public Result MenuAdd(@RequestBody Setmeal setmeal,Integer[] checkgroupIds){
        log.info("检查套餐添加 套餐id:{},套餐的检查组ids:{}",setmeal,checkgroupIds);
        checkMenuService.MenuAdd(setmeal,checkgroupIds);
        return new Result(true,MessageConstant.ADD_SETMEAL_SUCCESS);
    }

    /**
     * 根据套餐id回显套餐数据
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id回显套餐数据")
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据套餐id回显套餐数据 id:{}",id);
        Setmeal setmeal = checkMenuService.findById(id);
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }

    /**
     * 根据套餐id查询检查组
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id查询检查组")
    @GetMapping("/findSetmealIdByCheckitemgroupIds/{id}")
    public Result findSetmealOftheCheckgroup(@PathVariable Integer id){
        log.info("根据套餐id查询检查组id:{}",id);
        Integer[] checkgroupIds = checkMenuService.findSetmealOftheCheckgroup(id);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkgroupIds);
    }

    /**
     * 编辑套餐
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @ApiOperation("编辑套餐")
    @PutMapping("/update")
    @PreAuthorize("hasAnyAuthority('SETMEAL_EDIT')")
    public Result update(@RequestBody Setmeal setmeal, Integer[] checkgroupIds){
        log.info("编辑套餐   套餐id:{},检查组ids:{}",setmeal,checkgroupIds);
        checkMenuService.update(setmeal,checkgroupIds);
        return new Result(true,MessageConstant.EDIT_SETMEAL_SUCCESS);
    }
    /**
     * 删除套餐
     * @param id
     * @return
     */
    @ApiOperation("删除套餐")
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('SETMEAL_DELETE')")
    public Result delete(@PathVariable Integer id){
        log.info("删除套餐id:{}",id);
        checkMenuService.delete(id);
        return new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }
}
